package com.tedu.food.sys.controller;

import com.tedu.food.common.vo.GoodsVo;
import com.tedu.food.common.vo.JsonResult;
import com.tedu.food.common.vo.PageObject;
import com.tedu.food.sys.entity.Goods;
import com.tedu.food.sys.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/***
 * Goods(商品Controller控制类)
 * 
 * @version 创建时间：2019年11月22日 下午17:01:41
 */

@RestController
@RequestMapping("/goods/")
public class GoodsController {
	@Autowired
	private GoodsService goodsService;

	@RequestMapping("doFindPageObjects")
	public JsonResult doFindPageObjects(String goodsName, Integer pageCurrent, Integer categoryId) {
		PageObject<GoodsVo> pageObject = goodsService.findPageObjects(goodsName, pageCurrent, categoryId);
		return new JsonResult(pageObject);
	}

	@RequestMapping("doDeleteObjects")
	public JsonResult doDeleteGoodsObjectById(Integer... ids) {
		goodsService.deleteGoodsObjectById(ids);
		return new JsonResult("delete ok");
	}

	@RequestMapping("doUpdateGoodsObject")
	public JsonResult doUpdateGoodsObject(Goods goods) {
		System.out.println(goods);
		goodsService.updateGoodsObject(goods);
		return new JsonResult("update ok");
	}

	@RequestMapping("doValidById")
	public JsonResult doValidById(Integer id, Integer goodsStatus) {
		goodsService.validById(id, goodsStatus);
		return new JsonResult("update ok|修改成功");
	}

	@RequestMapping("doLoadCategoryName")
	public JsonResult doLoadCategoryName() {
		return new JsonResult(goodsService.findAllCategory());
	}

	@RequestMapping("doSaveGoodsObject")
	public JsonResult saveGoodsObject(Goods goods) {
		return new JsonResult(goodsService.saveGoodsObject(goods));
	}

}
